import java.sql.*;

public class JDBC2 {
    public static void main(String[] args) {
        try{
            Class.forName("com.mysql.cj.jdbc.Driver");//加载数据库驱动
            String url="jdbc:mysql://localhost:3306/test";//数据库连接子协议
            Connection conn= DriverManager.getConnection(url,"root","666666");
            Statement stmt=conn.createStatement();
            ResultSet rs=stmt.executeQuery("select * from student");
            while(rs.next()){//不断指向下一条记录
                System.out.println("id:"+rs.getInt(1));
                System.out.println("\tname:"+rs.getString(2));
            }
            rs.close();
            stmt.close();
            conn.close();
        }catch(ClassNotFoundException e){
            System.out.println("找不到指定的驱动程序类！");
        }catch(SQLException e){
            e.printStackTrace();
        }


    }
}
